package com.teng.mrliuproject.ui.activity

import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.bumptech.glide.Glide
import com.teng.mrliuproject.R
import com.teng.mrliuproject.base.Global
import com.teng.mrliuproject.base.RouteManages
import com.teng.mrliuproject.databinding.ActivityUpdateBinding
import com.teng.mrliuproject.ui.vmodel.UpdateVModel
import com.teng.mylibrary.base.BaseActivity
import com.teng.mylibrary.util.SPUtil
import com.teng.mylibrary.util.update.UpdateAppUtil

/**
 * Description:    关于我们
 * Author:         liuteng
 * CreateDate:     2022年1月10日
 * UpdateRemark:   更新说明
 */
@Route(path = RouteManages.UPDATE_ACTIVITY)
class UpdateActivity : BaseActivity<ActivityUpdateBinding, UpdateVModel>(),UpdateAppUtil.UpdateCallback {
    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_update
    }

    override fun initViewModel(): UpdateVModel {
        return ViewModelProvider(this).get(UpdateVModel::class.java)
    }

    override fun initView() {
        binding.viewmodel = viewModel
        viewModel.versionName.set("v${packageManager.getPackageInfo(packageName, 0).versionName}")

        viewModel.myUc.showQrCodeNotify.observe(this, {
            binding.ivErcode.setImageBitmap(it)
        })
        viewModel.myUc.checkUpdate.observe(this, {
            //检测版本更新
            UpdateAppUtil.checkUpdate(this, this,SPUtil.getIp() + Global.UPDATE_URL)
        })
    }

    override fun initData() {
        viewModel.zxing(SPUtil.getIp() + Global.UPDATE_APK_PATH)
    }

    override fun onUpdateResponse(msg: String) {
        println(msg)
    }


}